package club.laowang.chain.validation;

import club.laowang.chain.annotation.Length;
import club.laowang.chain.annotation.Max;
import club.laowang.chain.execption.ValidatorException;

public class LengthValidatorHandler implements ValidatorHandler{
    private Length length;

    public LengthValidatorHandler(Length length) {
        this.length = length;
    }

    @Override
    public void validator(Object value, ValidatorContext context) {
        if (value instanceof String) {
            String stringValue = value.toString();
            if (stringValue.length() != length.value()) {
                context.appendError("当前值为：" + stringValue + "，不等于规定长度值：" + length.value());
            }
        }
    }
}
